<?php
	//$_REQUEST['imsi_code']="460030912121001";
	//$_REQUEST['imsi_code']="999999999999982";
	$imsi = !empty($_REQUEST['imsi_code']) ? $_REQUEST['imsi_code'] : NULL;
	if($imsi==NULL) {
		echo 0;		exit;
	}
	//echo 'sdfsdf';
	$gameName = !empty($_REQUEST['gameName']) ? $_REQUEST['gameName'] : NULL;
	if($gameName==NULL) {
		echo 0;		exit;
	}
	//echo 'sdf';
	$currentTime = !empty($_REQUESTT['time']) ? $_REQUESTT['time'] : date('Y-m-d');
	$returnNum = 0;
	//数据库操作
	$conn = mysql_connect('localhost','root','') or die("connect db err:".mysql_error);
	mysql_select_db('info_push') or die("select db err:".mysql_error);
	mysql_query('set names utf8');	
	//查询是否有对应手机的当天登陆记录
	$query = "select id from login_info where imsi_code='{$imsi}' and first_login_time='{$currentTime}' and gamename='{$gameName}'";
	//插入手机的信息
	$insQuery="insert into login_info(`imsi_code`,`first_login_time`,`gamename`) values('{$imsi}','{$currentTime}','{$gameName}')";
	//echo $insQuery;	
	//exit;
	$result = mysql_query($query,$conn);	
	
	//没有对应手机当天记录
	if(mysql_num_rows($result)==0) {
		//查询是否有手机记录
		$res = mysql_query("select id from login_info where imsi_code='{$imsi}' and gamename='{$gameName}'",$conn);
	
		if(mysql_num_rows($res)==0)//没有记录，向数据库插入数据
			mysql_query($insQuery,$conn) or die('insQuery error'.mysql_error);	
		else//更新登陆日期
			mysql_query("update login_info set first_login_time='{$currentTime}' where `imsi_code`='{$imsi}' and gamename='{$gameName}'");
		
		
		mysql_close($conn);	
		if(is_resource($res)) mysql_free_result($res);
		$returnNum = 1;
		echo $returnNum;
		exit;
	}
	else{
		$returnNum = 0;
	}
	mysql_close($conn);	 
	if(is_resource($result)) mysql_free_result($result);
	echo $returnNum; 	exit;